package com.pvdnc.dxhook;

import android.util.Log;

import com.google.dexmaker.MethodId;
import com.google.dexmaker.TypeId;

public class ValueTypes {
    private static final String TAG=ValueTypes.class.getSimpleName();

    private static TypeId<ValueTypes> utilType = TypeId.get(ValueTypes.class);
    private static TypeId<Integer> IntegerType = TypeId.get(Integer.class);
    private static TypeId<Long> LongType = TypeId.get(Long.class);
    private static TypeId<Short> ShortType = TypeId.get(Short.class);
    private static TypeId<Double> DoubleType = TypeId.get(Double.class);
    private static TypeId<Boolean> BooleanType = TypeId.get(Boolean.class);
    private static TypeId<Float> FloatType = TypeId.get(Float.class);
    private static TypeId<Byte> ByteType= TypeId.get(Byte.class);
    private static TypeId<Character> CharacterType= TypeId.get(Character.class);

    private static MethodId Integer_value=IntegerType.getMethod(IntegerType,"valueOf",TypeId.INT);
    private static MethodId Long_value=LongType.getMethod(LongType,"valueOf",TypeId.LONG);
    private static MethodId Short_value=ShortType.getMethod(ShortType,"valueOf",TypeId.SHORT);
    private static MethodId Double_value=DoubleType.getMethod(DoubleType,"valueOf",TypeId.DOUBLE);
    private static MethodId Boolean_value=BooleanType.getMethod(BooleanType,"valueOf", TypeId.BOOLEAN);
    private static MethodId Float_value=FloatType.getMethod(FloatType,"valueOf",TypeId.FLOAT);
    private static MethodId Byte_value=ByteType.getMethod(ByteType,"valueOf",TypeId.BYTE);
    private static MethodId Char_value=CharacterType.getMethod(CharacterType,"valueOf",TypeId.CHAR);

    private static MethodId int_value=IntegerType.getMethod(TypeId.INT,"intValue");
    private static MethodId long_value=LongType.getMethod(TypeId.LONG,"longValue");
    private static MethodId short_value=ShortType.getMethod(TypeId.SHORT,"shortValue");
    private static MethodId double_value=DoubleType.getMethod(TypeId.DOUBLE,"doubleValue");
    private static MethodId boolean_value=BooleanType.getMethod(TypeId.BOOLEAN,"booleanValue");
    private static MethodId float_value=FloatType.getMethod(TypeId.FLOAT,"floatValue");
    private static MethodId byte_value=ByteType.getMethod(TypeId.BYTE,"byteValue");
    private static MethodId char_value=CharacterType.getMethod(TypeId.CHAR,"charValue");

    private static TypeId getTypeIdFromClass(Class cls){
        if(cls.getName().equals(int.class.getName())){
            return TypeId.INT;
        }else if(cls.getName().equals(long.class.getName())){
            return TypeId.LONG;
        }else if(cls.getName().equals(short.class.getName())){
            return TypeId.SHORT;
        }else if(cls.getName().equals(double.class.getName())){
            return TypeId.DOUBLE;
        }else if(cls.getName().equals(boolean.class.getName())){
            return TypeId.BOOLEAN;
        }else if(cls.getName().equals(float.class.getName())){
            return TypeId.FLOAT;
        }else if(cls.getName().equals(byte.class.getName())){
            return TypeId.BYTE;
        }else if(cls.getName().equals(char.class.getName())){
            return TypeId.CHAR;
        }else if(cls.getName().equals(void.class.getName())){
            return TypeId.VOID;
        }else{
            return  TypeId.get(cls);
        }
    }
    private static TypeId getClassTypeFromClass(Class cls){
        if(cls.getName().equals(int.class.getName())){
            return IntegerType;
        }else if(cls.getName().equals(long.class.getName())){
            return LongType;
        }else if(cls.getName().equals(short.class.getName())){
            return ShortType;
        }else if(cls.getName().equals(double.class.getName())){
            return DoubleType;
        }else if(cls.getName().equals(boolean.class.getName())){
            return BooleanType;
        }else if(cls.getName().equals(float.class.getName())){
            return FloatType;
        }else if(cls.getName().equals(byte.class.getName())){
            return BooleanType;
        }else if(cls.getName().equals(char.class.getName())){
            return CharacterType;
        }
        return TypeId.get(cls);
    }

    public static TypeId getReferenceTypeFromType(TypeId<?> type){
        String typeName=type.getName();
        Log.d(TAG,"valued type:"+type);
        if(TypeId.INT.equals(type)){
            return IntegerType;
        }else if(TypeId.LONG.equals(type)){
            return LongType;
        }else if(TypeId.SHORT.equals(type)){
            return ShortType;
        }else if(TypeId.DOUBLE.equals(type)){
            return DoubleType;
        }else if(TypeId.BOOLEAN.equals(type)){
            return BooleanType;
        }else if(TypeId.FLOAT.equals(type)){
            return FloatType;
        }else if(TypeId.BYTE.equals(type)){
            return ByteType;
        }else if(TypeId.CHAR.equals(type)){
            return CharacterType;
        }else{
            return  null;
        }
    }

    public static MethodId getValueFromClass(Class cls){
        if(cls.getName().equals(int.class.getName())){
            return Integer_value;
        }else if(cls.getName().equals(long.class.getName())){
            return Long_value;
        }else if(cls.getName().equals(short.class.getName())){
            return Short_value;
        }else if(cls.getName().equals(double.class.getName())){
            return Double_value;
        }else if(cls.getName().equals(boolean.class.getName())){
            return Boolean_value;
        }else if(cls.getName().equals(float.class.getName())){
            return Float_value;
        }else if(cls.getName().equals(byte.class.getName())){
            return Byte_value;
        }else if(cls.getName().equals(char.class.getName())){
            return Char_value;
        }else{
            return  null;
        }
    }

    public static MethodId getValueFromType(TypeId<?> type){
        String typeName=type.getName();
        Log.d(TAG,"valued type:"+type);
        if(TypeId.INT.equals(type)){
            return Integer_value;
        }else if(TypeId.LONG.equals(type)){
            return Long_value;
        }else if(TypeId.SHORT.equals(type)){
            return Short_value;
        }else if(TypeId.DOUBLE.equals(type)){
            return Double_value;
        }else if(TypeId.BOOLEAN.equals(type)){
            return Boolean_value;
        }else if(TypeId.FLOAT.equals(type)){
            return Float_value;
        }else if(TypeId.BYTE.equals(type)){
            return Byte_value;
        }else if(TypeId.CHAR.equals(type)){
            return Char_value;
        }else{
            return  null;
        }
    }

    private static MethodId toValueFromClass(Class cls){
        if(cls.getName().equals(int.class.getName())){
            return int_value;
        }else if(cls.getName().equals(long.class.getName())){
            return long_value;
        }else if(cls.getName().equals(short.class.getName())){
            return short_value;
        }else if(cls.getName().equals(double.class.getName())){
            return double_value;
        }else if(cls.getName().equals(boolean.class.getName())){
            return boolean_value;
        }else if(cls.getName().equals(float.class.getName())){
            return float_value;
        }else if(cls.getName().equals(byte.class.getName())){
            return byte_value;
        }else if(cls.getName().equals(char.class.getName())){
            return char_value;
        }else{
            return  null;
        }
    }

    public static MethodId toValueFromType(TypeId<?> type){
        String typeName=type.getName();
        Log.d(TAG,"valued type:"+type);
        if(TypeId.INT.equals(type)){
            return int_value;
        }else if(TypeId.LONG.equals(type)){
            return long_value;
        }else if(TypeId.SHORT.equals(type)){
            return short_value;
        }else if(TypeId.DOUBLE.equals(type)){
            return double_value;
        }else if(TypeId.BOOLEAN.equals(type)){
            return boolean_value;
        }else if(TypeId.FLOAT.equals(type)){
            return float_value;
        }else if(TypeId.BYTE.equals(type)){
            return byte_value;
        }else if(TypeId.CHAR.equals(type)){
            return char_value;
        }else{
            return  null;
        }
    }
}
